package com.eway.viewanimator;

import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class KeyFragment_Activity extends AppCompatActivity implements View.OnClickListener {

	private Button telStart;
	private ImageView tell;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_key_fragment_);


		telStart = (Button) findViewById(R.id.tel_start);
		tell = (ImageView) findViewById(R.id.tell);

		telStart.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.tel_start:
				Keyframe keyframe = Keyframe.ofFloat(0, 0);
				Keyframe keyframe1 = Keyframe.ofFloat(0.1f, -20f);
				Keyframe keyframe2 = Keyframe.ofFloat(0.2f, 20f);
				Keyframe keyframe3 = Keyframe.ofFloat(0.3f, -20f);
				Keyframe keyframe4 = Keyframe.ofFloat(0.4f, 20f);
				Keyframe keyframe5 = Keyframe.ofFloat(0.5f, -20f);
				Keyframe keyframe6 = Keyframe.ofFloat(0.6f, 20f);
				Keyframe keyframe7 = Keyframe.ofFloat(0.7f, -20f);
				Keyframe keyframe8 = Keyframe.ofFloat(0.8f, 20f);
				Keyframe keyframe9 = Keyframe.ofFloat(0.9f, -20f);
				Keyframe keyframe10 = Keyframe.ofFloat(1f, 0f);


				PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofKeyframe("rotation",
						keyframe, keyframe1, keyframe2, keyframe3, keyframe4, keyframe5, keyframe6, keyframe7,
						keyframe8, keyframe9, keyframe10);

				Keyframe keyframe11 = Keyframe.ofFloat(0f, 1f);
				Keyframe keyframe12 = Keyframe.ofFloat(0.1f, 1.1f);
				Keyframe keyframe13 = Keyframe.ofFloat(0.2f, 1.1f);
				Keyframe keyframe14 = Keyframe.ofFloat(1f, 1.0f);

				PropertyValuesHolder propertyValuesHolder1 = PropertyValuesHolder.ofKeyframe("scaleX",
						keyframe11, keyframe12, keyframe13, keyframe14);


				Keyframe keyframe15 = Keyframe.ofFloat(0f, 1f);
				Keyframe keyframe16 = Keyframe.ofFloat(0.1f, 1.1f);
				Keyframe keyframe17 = Keyframe.ofFloat(0.2f, 1.1f);
				Keyframe keyframe18 = Keyframe.ofFloat(1f, 1.0f);

				PropertyValuesHolder propertyValuesHolder2 = PropertyValuesHolder.ofKeyframe("scaleY",
						keyframe15, keyframe16, keyframe17, keyframe18);


				ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(tell, propertyValuesHolder, propertyValuesHolder1, propertyValuesHolder2);
				objectAnimator.setDuration(1000);
				objectAnimator.start();
				break;
			default:
				break;
		}

	}
}
